package com.cy.java.util;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectUtil {

    /**
     * 基于传入的类型构建对象实例
     */

    public  static  Object newInstance(String pkgClass,
                                       Object[]args,
                                       Class<?>...parameterTypes) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException {
        Class cls = Class.forName(pkgClass);
        Constructor c = cls.getDeclaredConstructor(parameterTypes);
        c.setAccessible(true);
        return c.newInstance(args);
    }
}

